#include "SMARTSESUtil.h"

void SMARTSESInitializeData(double *A, double *B, double *C, double *D, T_SRC *tSrc, SES_SRC *sesSrc, 
	double **X, double *Y, int *n, double *steps, double *hfactor)
{
	int i;
	SMARTSESCheckMatrix(A, B, C, D, tSrc, sesSrc, n, steps, hfactor);
	if(*n == -1)
	{
		printf("Matrix Scale is Not Found! Please Check For the Matrix!\n");
		exit(1);
	}
	//Generate X and Y
	if(*X != NULL)
		SMARTDELETE(*X);	
	*X = SMARTNEW(double, *n);
	for(i = 0; i < (*n); i++)
		(*X)[i] = 0;
	*Y = 0	;
}

void SMARTSESCheckMatrix(double *A, double *B, double *C, double *D, T_SRC *tSrc, SES_SRC *sesSrc,
	int *n, double *steps, double *hfactor)
{
	T_SRC *tp = tSrc;
	SES_SRC *sestp = NULL;
	//ToDo: Dicide where n determines
	*n = 2;
	*steps = -1;
	*hfactor = -1;
	
	while(tp != NULL)
	{
		sestp = SMARTNEW(SES_SRC, 1);
		switch(tp->type)
		{
			case 1:	//DC(1)

				break;
			case 2:	//AC(1)
				
				break;
			case 3:	//PULSE(7)
				
				break;
			case 4:	//SIN(6)
			
				break;
			case 5:	//EXP(6)
					
				break;
			default:

				break;
		}
		tp = tp->next;		
	}	
	//Maybe some triks left here
	if(sestp != NULL)
	{
		SES_SRC *sesttp = sesSrc;
		if(sesttp != NULL)
		{
			while(sesttp->next != NULL)
				sesttp = sesttp->next;
		}		
		sesttp->next = sestp;		
	}
}

void SMARTSESDispose(SES_SRC *sesSrc, double *X)
{	
	if(X != NULL)
		SMARTDELETE(X);
	SES_SRC *tp = sesSrc;
	while(tp != NULL)
	{
		SES_SRC *ttp = tp;
		tp = tp->next;
		free(ttp);		
	}
}
